// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async(event, context) => {
  const wxContext = cloud.getWXContext()
  const rst = await db.collection('userInfo').where({
    _openid: wxContext.OPENID
  }).get({
    success: res => {
      console.log(res)
    },
    fail: err => {
      console.log(err)
    }
  })
  var length=rst.data.length;
  var answertime=rst.data[0].answertimes;
  var passtime=rst.data[0].passtimes;
  var topscore=rst.data[0].topscore;
  var passrate=Math.round(passtime/answertime*100);//通过率直接取整
  return {
    length: length,
    answertime:answertime,
    passtime:passtime,
    topscore:topscore,
    passrate:passrate
  }
}